<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="com.sz.common.ICommonDAO" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String primary_business_id = request.getParameter("primary_business_id");
if(primary_business_id == null || primary_business_id.length() == 0) {
	primary_business_id = "-1";
}

%>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<link href="<%= request.getContextPath() %>/css/main.css" rel="stylesheet" type="text/css" />
		<base href="<%=basePath%>">

		<title></title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="">
		<meta http-equiv="description" content="">
		
		<style type="text/css"> 
			@import "js/tableview/TableView.css";
    	</style>
	</head>
	
	<body onload="onLoad()">		
		<script type="text/javascript" src="js/jquery.js"></script>
		<script type="text/javascript" src="js/tableview/SortView.js"></script>
		<script type="text/javascript" src="js/tableview/PagerView.js"></script>
		<script type="text/javascript" src="js/tableview/TableView.js"></script>
		<script type="text/javascript" src="js/tableview/SelectorView.js"></script>
		<script type="text/javascript" src="js/tableview/PaperView.js"></script>
		<script type="text/javascript" src="js/utility.js"></script>
	  	
	<table width="100%">
		  <tr>
		  	<td class="title0" >商家推荐</td>		  	
	  	  </tr>	  	
	 </table>
	  	
 	<table width="100%">
  		<tr>
	  		<td>
			  	<div id="table_div" style= "width: 100%"></div>
				<div id="pager"></div>
			</td>
		</tr>
  	</table>

  	
  	<SCRIPT LANGUAGE="JavaScript">
  	
  		var numPerPage = 10; //每页行数
		var paramValue = "";
		var methodCount = "";
		var methodPage = "";
		
		var table = new TableView('table_div');
		table.header = {
			BUSINESS_ID			: '商家编号',
			NAME				: '商家名称',
			REGION_FULLNAME		: '区域',
			ADDRESS				: '地址',
			TEL1				: '预订电话',
			DISCOUNT			: '折扣',
			MAIN_SERIAL			: '主营菜系',
			AVG_FEE				: '人均消费',
			ORDER_DEMAND		: '预订要求',
			CHECK_STATUS		: '已签约',
			DETAIL				: '详细信息',
			OPERATE				: '操作'		
		};		
		table.customDefine = {
			BUSINESS_ID			: '',
			NAME				: '',
			REGION_FULLNAME		: '',
			ADDRESS				: '',
			TEL1				: '',
			DISCOUNT			: '',
			MAIN_SERIAL			: '',
			AVG_FEE				: '',
			ORDER_DEMAND		: '',
			CHECK_STATUS		: '',
			DETAIL				: '',
			OPERATE				: ''		
		};
				
		table.dataKey = 'BUSINESS_ID';
		table.count = false;
		table.title = false;
		table.display.filter = false;
		table.display.pager = false;
		table.display.multiple = false;
		table.pager.size = numPerPage;

		var pager = new PagerView('pager');
		pager.onclick = onPagerClick;
		pager.itemCount = 0;
		pager.size = numPerPage;
		
		table.render();
		pager.render();

		function queryBusiness(pageNO, returnCount) {
  	  		var begin = (pageNO-1) * numPerPage + 1;
  	  		var end = pageNO * numPerPage;
  	  		var mc = returnCount==true ? methodCount : "";
  	  		var date = {
  	  			BEAN_METHOD 	: "TicketBMO.queryBusinessRecommand",
  	  			PARAM_CLASS 	: "java.util.Map",
  	    	  	PARAM_VALUE 	: paramValue,
  	    	  	METHOD_COUNT 	: mc, //为空则不返回记录数
  	    	  	METHOD_PAGE 	: methodPage, //为空则不分页
  	    	  	PAGE_BEGIN 		: begin, //仅在METHOD_PAGE不为空时使用
  	    	  	PAGE_END 		: end
  	  	    };
  	  		$.ajax({
				type: "POST",
				url: "query.exec",
				//data: {id:'123'},
				data: date,
				datatype:"json",
				success: query_success,
				error: show_error
  	  		});
  	  	}
  	  	
  	  	function onPagerClick(pageNO) {
  			queryBusiness(pageNO, "FLASE");
  		}
  	  	
  	  	//刷新当前页
  		function refreshCurrentPage() {
  			queryBusiness(pager.index, "FLASE");
  		}  		
  		
  		function query_success(data) {
  	  		var jdata = eval("(" + data + ")");
  	  		if(jdata.COUNT != null) { //有记录数返回  	  	  		
  	  	  		pager.itemCount = jdata.COUNT;
  	  	  		pager.size = numPerPage;  	  	  		
  	  	  		pager.render();
  	  		} 
		   var array = eval(jdata.LIST);
		   for(var i = 0; i < array.length; ++i) {
		   		//形如：<a href="javascript:" onclick="about()">modal</a>
		   		var url = "<a href=\"javascript:\" onclick=\"onBusinessDetail('";
		   		url += array[i].BUSINESS_ID;
		   		url += "')\">详细信息</a>";
		   		array[i].DETAIL = url;
		   		
		   		url = "<input type=\"button\" value=\"选择\" onclick=\"onSelect('";
		   		url += array[i].BUSINESS_ID;		  
		   		url += "')\" />";
		   		array[i].OPERATE = url;		   		
		   }
		   table.clear();
		   table.addRange(array);
		}
  		function show_error(data) {
  			var err = "操作失败！\n";
  			err += "status：" + data.status + "\n";
  			err += "statusText：" + data.statusText;
  	  		alert(err);
 		}
 		
 		function onBusinessDetail(business_id) {
 			var url = "<%=path%>";
  			url += "/page/viewBusiness.jsp?business_id=" + business_id;
  			var param = "status:no;scroll:yes;dialogWidth:1024px;dialogHeight:600px";
			//window.showModalDialog(url, window, param);
			
			var width = 1024; //弹出窗口的宽度;
			var height = 600; //弹出窗口的高度;
			var top = (window.screen.availHeight-30-height)/2; //获得窗口的垂直位置;
			var left = (window.screen.availWidth-10-width)/2; //获得窗口的水平位置;
			var style = "toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no";			
			window.open (url,"商家信息","height="+height+",width="+width+",top="+top+",left="+left+","+style);
 		}
 		
 		function onSelect(business_id) { 			
 			window.opener.callback_businessRecommand(business_id);
 		}
 		
 		function onLoad() {
 			var primary_business_id = "<%=primary_business_id%>";
 			if(primary_business_id == "-1") {
 				return; //未传过来参数
 			}
 			
 			paramValue = "{";
			
			paramValue += " PRIMARY_BUSINESS_ID:'" + primary_business_id;  //按目前的逻辑，region_id一直不为空
			paramValue += "'";
			
			
			paramValue += "}";
			
			pager.index = 1;
  	  		queryBusiness(1, false); //不分页 
 		}  	

  	</SCRIPT>
	</body>
</html>
